package org.dromara.xyyw.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.xyyw.domain.bo.XyywShopProductCollectBo;
import org.dromara.xyyw.domain.query.XyywShopProductCollectQuery;
import org.dromara.xyyw.domain.vo.XyywShopProductCollectVo;
import org.dromara.xyyw.service.IXyywShopProductCollectService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 商铺商品收藏
 *
 * @author yf
 * @date 2024-05-29
 */
@Validated
@RestController
@RequestMapping("/xyyw/shopProductCollect")
public class XyywShopProductCollectController extends BaseController {

    @Autowired
    private IXyywShopProductCollectService xyywShopProductCollectService;

    /**
     * 查询商铺商品收藏列表
     */
    @SaCheckPermission("xyyw:shopProductCollect:list")
    @GetMapping("/list")
    public TableDataInfo<XyywShopProductCollectVo> list(XyywShopProductCollectQuery query) {
        return xyywShopProductCollectService.queryPageList(query);
    }

    /**
     * 导出商铺商品收藏列表
     */
    @SaCheckPermission("xyyw:shopProductCollect:export")
    @Log(title = "商铺商品收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(XyywShopProductCollectQuery query, HttpServletResponse response) {
        List<XyywShopProductCollectVo> list = xyywShopProductCollectService.queryList(query);
        ExcelUtil.exportExcel(list, "商铺商品收藏", XyywShopProductCollectVo.class, response);
    }

    /**
     * 获取商铺商品收藏详细信息
     *
     * @param shopProductCollectId 主键
     */
    @SaCheckPermission(value = {"xyyw:shopProductCollect:query", "xyyw:shopProductCollect:edit"}, mode = SaMode.OR)
    @GetMapping("/{shopProductCollectId}")
    public R<XyywShopProductCollectVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long shopProductCollectId) {
        return R.ok(xyywShopProductCollectService.queryById(shopProductCollectId));
    }

    /**
     * 新增商铺商品收藏
     */
    @SaCheckPermission("xyyw:shopProductCollect:add")
    @Log(title = "商铺商品收藏", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody XyywShopProductCollectBo bo) {
        return toAjax(xyywShopProductCollectService.insertByBo(bo));
    }

    /**
     * 修改商铺商品收藏
     */
    @SaCheckPermission("xyyw:shopProductCollect:edit")
    @Log(title = "商铺商品收藏", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody XyywShopProductCollectBo bo) {
        return toAjax(xyywShopProductCollectService.updateByBo(bo));
    }

    /**
     * 删除商铺商品收藏
     *
     * @param shopProductCollectIds 主键串
     */
    @SaCheckPermission("xyyw:shopProductCollect:remove")
    @Log(title = "商铺商品收藏", businessType = BusinessType.DELETE)
    @DeleteMapping("/{shopProductCollectIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] shopProductCollectIds) {
        return toAjax(xyywShopProductCollectService.deleteWithValidByIds(List.of(shopProductCollectIds)));
    }
}
